//
//  XS_DownloadStartListCell.swift
//  XueDao
//
//  Created by Mac on 2020/12/29.
//

import UIKit

protocol XS_DownloadStartListCellDelegate {
    func listCell(listCell : XS_DownloadStartListCell, didClickSelectBtn:UIButton)
}

class XS_DownloadStartListCell: UITableViewCell {
    
    var delegate : XS_DownloadStartListCellDelegate?
    
    var _model : XS_KCcurriculumHourDtoListM!
    public var model : XS_KCcurriculumHourDtoListM!{
        set{
            _model = newValue
            //设置数据
            titleLabel.text = newValue.curriculumHourName
            selectBtn.isSelected = newValue.selected
            contentLabel.text = newValue.duration
            if newValue.progress > 0 {
                contentLabel.text = String(newValue.progress) + "% "+newValue.duration + "|"+newValue.videoSize
                selectBtn.isEnabled = newValue.isManage
            }else{
                selectBtn.isEnabled = true
            }
        }
        get{
            return _model
        }
    }
    
    var _canDownload : Bool = false
    public var canDownload: Bool{
        set{
            _canDownload = newValue
            //设置数据
            if _model.progress > 0 {
                contentLabel.text = String(_model.progress) + "% "+_model.duration + "|" + _model.videoSize
                titleLabel.text = _model.curriculumHourName
                selectBtn.isHidden = false
            }else{
                contentLabel.text = canDownload ? _model.duration + "|" + _model.videoSize : ""
                selectBtn.isHidden = !newValue
                titleLabel.text = canDownload ? _model.curriculumHourName : ""
            }
            
        }
        get{
            return _canDownload
        }
    }
    
    var _isShow : Bool = false
    public var isShow: Bool{
        set{
            _isShow = newValue
            //设置数据
            if _model.progress < 100 && _model.progress > 0 {
                contentLabel.text = String(_model.progress) + "% "+_model.duration + "|" + _model.videoSize
                titleLabel.text = _model.curriculumHourName
                selectBtn.isHidden = false
            }else{
                contentLabel.text = _isShow ? _model.duration + "|" + _model.videoSize : ""
                selectBtn.isHidden = !newValue
                titleLabel.text = _isShow ? _model.curriculumHourName : ""
            }
        }
        get{
            return _canDownload
        }
    }

    @IBOutlet weak var selectBtn: UIButton!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var contentLabel: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    @IBAction func selectBtnAction(_ sender: UIButton) {
        if delegate != nil {
            delegate?.listCell(listCell: self, didClickSelectBtn: sender)
        }
    }
    
    class func getCellHeight(model : XS_KCcurriculumHourDtoListM) -> CGFloat{
        return model.progress == 100 ? 64 : 0
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
